package com.atguigu.yygh.user.api;

import com.alibaba.nacos.client.naming.net.HttpClient;
import com.atguigu.yygh.user.service.PatientService;
import com.haust.su.ghyy.common.result.Result;
import com.haust.su.ghyy.common.utils.AuthContextHolder;
import com.haust.su.ghyy.model.user.Patient;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author haustsusu
 * @create 2023-05-07-13:39
 */
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {
    @Autowired
    private PatientService patientService;

    //获取就诊人列表
    @GetMapping("auth/findAll")
    public Result findAll(HttpServletRequest request){
        Long userId=AuthContextHolder.getUserId(request);
        List<Patient> list=patientService.findAllUserId(userId);
        //
        return Result.ok(list);

    }


    //添加就诊人操作
    @PostMapping("auth/save")
    public Result savePatient(@RequestBody Patient patient,HttpServletRequest request){
        //获取当前登录的用户id
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }


    //根据id查询就诊人的信息
    //由于直接查patient的信息不够完整,这里自定义这个方法
    @GetMapping("auth/get/{id}")
    public Result getPatient(@PathVariable long id){
        Patient patient= patientService.getPatientId(id);
        return Result.ok(patient);
    }



    //修改就诊人信息
    @PostMapping("auth/update")
    public Result updatePatient(@RequestBody Patient patient){
        //获取当前登录的用户id
        patientService.updateById(patient);
        return Result.ok();
    }



    //删除就诊人的信息
    @DeleteMapping("auth/remove/{id}")
    public Result removePatient(@PathVariable long id){
        //获取当前登录的用户id
        patientService.removeById(id);
        return Result.ok();
    }


    //根据就诊人的id 获取就诊人的信息,
    //虽然这个方法上面已经写过,但是这里可以用作内部调用使用
    @ApiOperation(value = "获取就诊人")
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(
            @PathVariable Long id) {

        return patientService.getPatientId(id);

    }




}
